using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using FE;

namespace WinFE
{
    public partial class GameForm : Form
    {
        Dictionary<Button, GameAdapter.Actions> ButtonActions = new Dictionary<Button, GameAdapter.Actions>();
        Dictionary<GameAdapter.Actions, Button> ActionButtons = new Dictionary<GameAdapter.Actions, Button>();
        List<Button> Buttons = new List<Button>();
        WinFormsAdapter adapter;

        delegate void SetControlsCallback(GameAdapter.Actions[] actions);
        delegate void HideControlsCallback();
        public GameForm(WinFormsAdapter adapter)
        {
            this.adapter = adapter;
            InitializeComponent();

            foreach (GameAdapter.Actions action in Enum.GetValues(typeof(GameAdapter.Actions)))
            {
                Button b = new Button();

                b.Click += new EventHandler(buttonPress);                
                b.Size = new Size(80, 28);                
                b.TextAlign = ContentAlignment.MiddleLeft;
                b.Font = new Font("Verdana", 8, FontStyle.Bold);
                b.Text = Enum.GetName(typeof(GameAdapter.Actions), action);
                ButtonActions[b] = action;
                ActionButtons[action] = b;
                Buttons.Add(b);
            }

            Focus();

        }
        public void ShowActions(params GameAdapter.Actions[] actions)
        {
            if (flowLayoutPanel1.InvokeRequired)
            {
                SetControlsCallback d = new SetControlsCallback(ShowActions);
                Invoke(d, new object[] { actions });
            }
            else
            {
                foreach (GameAdapter.Actions action in actions)
                {
                    flowLayoutPanel1.Controls.Add(ActionButtons[action]);
                }
            }

        }
        public void HideActions()
        {
            if (flowLayoutPanel1.InvokeRequired)
            {
                HideControlsCallback d = new HideControlsCallback(HideActions);
                Invoke(d, new object[] {});
            }
            else
            {
                flowLayoutPanel1.Controls.Clear();
            }
        }
        public void buttonPress(object sender, EventArgs e)
        {
            adapter.ActionChosen(ButtonActions[sender as Button]);
        }

        public SplitterPanel getPanel()
        {
            return this.splitContainer2.Panel1;
        }

        public void SetQuickStatus(string message)
        {
            this.label1.Text = message;
        }
        string statusText = string.Empty;

        public void SetDetailStatus(string message)
        {
            statusText = message + '\n' + statusText;
            this.textBox1.Lines = statusText.Split('\n');
        }
    }
    public class InvokeRequiredAction
    {
        public InvokeRequiredAction(Control control)
        {

        }
    }
}